﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;
namespace HNQXYJ.HN_User
{
    public partial class UserUpdatePwdByUserName : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = Session["username"].ToString();
            this.txtUserName.Text = username;
        }

        //protected void reset_Click(object sender, ImageClickEventArgs e)
        //{

        //}

        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            string username = Session["username"].ToString();
            UsersBLL ub = new UsersBLL();
            Users user = ub.GetUserByUserName(username);
            if (user != null)
            {
                string oldPwd =UsersBLL.GetMD5( this.txtOldPwd.Text.Trim());
                if (oldPwd.Equals(user.Password))//旧密码输入正确
                {
                    user.Password = UsersBLL.GetMD5(this.txtNewPwd.Text.Trim());
                    if (!this.txtNewPwd.Text.Trim().Equals(this.txtConfirmPwd.Text.Trim()))
                    {
                        this.Label1.Text = "新密码两次输入不一致";
                        return;
                    }
                    else
                    {
                        bool flage = ub.UpateUserPassword(user);
                        if (flage)
                        {
                            this.Label1.Text = "密码更新成功";
                            return;
                        }
                        else
                        {
                            this.Label1.Text = "密码更新成功";
                            return;
                        }
                    }
                }
                else
                {
                    this.Label1.Text = "你输入的旧密码不正确";
                    return;
                }

            }
        }
    }
}